package com.ruoyi.web.controller.easywenku;

import java.util.Arrays;
import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.easywenku.entity.PromotionEducation;
import com.ruoyi.easywenku.service.PromotionEducationService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * baomingController
 *
 * @author ruoyi
 * @date 2021-07-07
 */
@Controller
@RequestMapping("/easywenku/education")
public class PromotionEducationController extends BaseController
{
    private String prefix = "easywenku/education";

    @Autowired
    private PromotionEducationService promotionEducationService;

    @RequiresPermissions("easywenku:education:view")
    @GetMapping()
    public String education()
    {
        return prefix + "/education";
    }

    /**
     * 查询baoming列表
     */
    @RequiresPermissions("easywenku:education:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PromotionEducation promotionEducation)
    {
        startPage();
        List<PromotionEducation> list = promotionEducationService.list(new QueryWrapper<>(promotionEducation));
        return getDataTable(list);
    }

    /**
     * 导出baoming列表
     */
    @RequiresPermissions("easywenku:education:export")
    @Log(title = "baoming", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PromotionEducation promotionEducation)
    {
        List<PromotionEducation> list = promotionEducationService.list(new QueryWrapper<>(promotionEducation));
        ExcelUtil<PromotionEducation> util = new ExcelUtil<PromotionEducation>(PromotionEducation.class);
        return util.exportExcel(list, "education");
    }

    /**
     * 新增baoming
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存baoming
     */
    @RequiresPermissions("easywenku:education:add")
    @Log(title = "baoming", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PromotionEducation promotionEducation)
    {
        return toAjax(promotionEducationService.save(promotionEducation));
    }

    /**
     * 修改baoming
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        PromotionEducation promotionEducation = promotionEducationService.getById(id);
        mmap.put("promotionEducation", promotionEducation);
        return prefix + "/edit";
    }

    /**
     * 修改保存baoming
     */
    @RequiresPermissions("easywenku:education:edit")
    @Log(title = "baoming", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PromotionEducation promotionEducation)
    {
        return toAjax(promotionEducationService.updateById(promotionEducation));
    }

    /**
     * 删除baoming
     */
    @RequiresPermissions("easywenku:education:remove")
    @Log(title = "baoming", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(promotionEducationService.removeByIds(Arrays.asList(ids.split(","))));
    }
}
